package com.dailyblue.smbms.controller;

import com.alibaba.fastjson2.JSONArray;
import com.dailyblue.smbms.bean.User;
import com.dailyblue.smbms.service.UserService;
import com.dailyblue.smbms.service.impl.UserServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user_find_id")
public class UserFindByIdController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        UserService service = new UserServiceImpl();
        User user = service.findById(id);
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        String json = JSONArray.toJSONString(user);
        out.println(json);
    }
}